#ifndef __STRING_FUNCTIONS_HPP__
#define __STRING_FUNCTIONS_HPP__

#include <cctype>
#include <iostream>
#include <string.h>

namespace std {

inline bool is_uint(const std::string &str) {
    size_t len = str.length();
    for (unsigned int i = 0; i < len; i++)
        if (!isdigit(str[i]))
            return false;
    return true;
}

inline bool is_int(const std::string &str) {
    size_t len = str.length();
    unsigned int st = 0;
    if (str[0] == '-' || str[0] == '+')
        st = 1;
    for (unsigned int i = st; i < len; i++)
        if (!isdigit(str[i]))
            return false;
    return true;
}

inline bool is_float(const std::string &str) {
    size_t len = str.length();
    unsigned int i = 0;
    if (str[0] == '-' || str[0] == '+')
        i = 1;
    while (i < len && isdigit(str[i]))
        i++;
    if (i >= len)
        return true;
    if (str[i] != '.')
        return false;
    i++;
    while (i < len && isdigit(str[i]))
        i++;
    if (i >= len)
        return true;
    return false;
}

inline std::string dir_name(const std::string &str) {
    size_t pos = str.rfind('/');
    if (pos == std::string::npos)
        return std::string();
    else
        return str.substr(0, pos + 1);
}

inline bool ends_with(const std::string &str, const std::string &end) {
    size_t sl = str.length();
    size_t el = end.length();
    if (sl < el)
        return false;
    return str.substr(sl - el).compare(end) == 0;
}

};

#endif
